package com.itzmn.thread.lock;

import javafx.concurrent.Worker;

/**
 * @Author: 张梦楠
 * @Date: 2018/12/15 15:43
 * 简书：https://www.jianshu.com/u/d611be10d1a6
 * 码云：https://gitee.com/zhangqiye
 * @Description:
 */
public class AQSTest {

    public void test(){
        TwoThreadLock lock = new TwoThreadLock();

        class Worker extends Thread{
            @Override
            public void run() {
                while (true){

                    lock.lock();
                    try {
                        sleep(1000);
                        System.out.println(Thread.currentThread().getName());
                        sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }finally {

                        lock.unlock();
                    }

                }
            }
        }

        for (int i = 0;i<10;i++){
            Worker worker = new Worker();
            worker.start();
        }

    }
    public static void main(String[] args) {

        new AQSTest().test();

    }

}
